//
//  YHBottomView.m
//  FAKER
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 YHLai. All rights reserved.
//

#import "YHBottomView.h"
#import "FitHeader.h"

@implementation YHBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        _backButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [_backButton setBackgroundImage:[UIImage imageNamed:@"common_icon_return@2x"] forState:UIControlStateNormal];
//        _backButton.backgroundColor = [UIColor orangeColor];
        [_backButton addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        _backButton.tag = 1000;
        [self addSubview:_backButton];
        
        _refreshButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [_refreshButton setBackgroundImage:[UIImage imageNamed:@"common_icon_refresh_2@2x"] forState:UIControlStateNormal];
//        _refreshButton.backgroundColor = [UIColor orangeColor];
        [_refreshButton addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        _refreshButton.tag = 1001;
        [self addSubview:_refreshButton];
        
        _lineView = [[UIView alloc] init];
        [self addSubview:_lineView];
        
        //添加夜间模式监听
        [self changeColor];
        ADD_NSNOTIFICATIONCENTER_OBSERVER;
    }
    return self;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, -1, SCREEN_WIDTH, 1)];
//    _lineView.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.9 alpha:1];
//    [self addSubview:_lineView];
    _lineView.frame = CGRectMake(0, -.5, SCREEN_WIDTH, .5);
    
    _backButton.frame = CGRectMake(20 * FITWIDTH, 5, 30, 30);
    _refreshButton.frame = CGRectMake(SCREEN_WIDTH - _backButton.X - 30, _backButton.Y, _backButton.WIDTH, _backButton.HEIGHT);
}

#pragma mark - 点击方法
- (void)clickButtonAction:(UIButton *)button
{
    if (button.tag == 1000) {
        _block(@"back");
    }
    else {
        _block(@"refresh");
    }
}

- (void)changeColor
{
    if (NSUSERDEFAULTS_NIGHT) {
        self.backgroundColor = BGCOLOR_BLACK;
        _lineView.backgroundColor = [UIColor darkGrayColor];
    } else {
        self.backgroundColor = [UIColor whiteColor];
        _lineView.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.9 alpha:1];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
